package com.atmc.service.impl;

import com.atmc.entity.*;
import com.atmc.mapper.DetailsOrderMapper;
import com.atmc.service.DetailsOrderService;
import com.atmc.service.GoodsOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @BelongsProject: SpringCloud1216
 * @BelongsPackage: com.atmc.service.impl
 * @Author: chuyings
 * @CreateTime: 2022-11-17  18:19
 * @Version: 1.0
 */
@Service
public class DetailsOrderServiceImpl implements DetailsOrderService {
    @Autowired
    DetailsOrderMapper detailsOrderMapper;
    @Autowired
    GoodsOrderService goodsOrderService;
    @Override
    public int insertDetailsOrder(DetailsOrder detailsOrder) {
        return detailsOrderMapper.insertDetailsOrder(detailsOrder);
    }

    @Override
    public DetailsOrder queryByDetailsNumber(Long detailsNumber) {
        return detailsOrderMapper.queryByDetailsNumber(detailsNumber);
    }

    @Override
    public List<DetailsData> goodsOrderAll(String userName) {
        List<GoodsOrder> goodsOrderAll = detailsOrderMapper.getGoodsOrderAll(userName);
        List<DetailsData> detailsDataList=new ArrayList<>();
        Long len=1122334455L;
        DetailsData detailsData;
        for (GoodsOrder goodsOrder : goodsOrderAll) {
            Long orderId = goodsOrder.getOrderId();
            goodsOrder.setOrderId(len+orderId);
            detailsData=new DetailsData(goodsOrder.getOrderId(),goodsOrder.getGoodsName(),goodsOrder.getSingPrice(),goodsOrder.getGoodsNum(),goodsOrder.getOrderStatus(),goodsOrder.getCreate_time());
            detailsDataList.add(detailsData);
        }
        return detailsDataList;
    }

    @Override
    public List<PetsInfo> selectAllPetsByUserName(String userName) {
        return detailsOrderMapper.selectAllPetsByUserName(userName);
    }

    @Override
    public ResponseResult myAdoption(String userName) {
        List<PetsInfo> petsInfos = detailsOrderMapper.selectAllPetsByUserName(userName);
        return new ResponseResult(200,"宠物列表",petsInfos);
    }

}
